package Gui;


import java.io.Serializable;

import javax.swing.JOptionPane;

import DB.PhraseConnector;
import General.Phrase;
import Interfaces.IRound;


public class Round implements Serializable, IRound{

	private static final long serialVersionUID = 1L;
	protected Player[] players;
	protected  int numofplayers;
	protected Phrase phrase;
	int roundBonus = 1000;
	int currentPlayerNum;
	protected IGame game;


	public Round(Player[] Players,int numofPlayers, int playernum) {
		players = Players;
		numofplayers=numofPlayers;
		currentPlayerNum=playernum;
		game = App.getGame();
	}

	public void Initiallize() {	

		game.getPanel_8().initPhrasePanel();
		phrase = PhraseConnector.getInstance().getRandomPhrase();
		game.getPanel_8().initPanelToPhrase(phrase);}
	//initRoundScores();}


	public void PlayRound() {
		game.lightthePlayer(currentPlayerNum%numofplayers);
		//phrase.getStatus();
		game.setCanspin(true);

		game.getInstructions().setText(players[currentPlayerNum%numofplayers].getName()+" click and hold the\n mouse over the wheel to spin it");
	}
	
	public Phrase getPhrase(){
		return phrase;
	}

	public void setAmount(int am) {
		players[currentPlayerNum%numofplayers].amount=am;
		players[currentPlayerNum%numofplayers].PlayTurn(phrase,this);	
	}


	public void endTurn(Player player){
		if (phrase.Guessed()){
			SetPlayersScore(currentPlayerNum%numofplayers);
			status_panel.println(players[currentPlayerNum%numofplayers].getName()+" won the round");
			JOptionPane.showMessageDialog(game.getPanel(),players[currentPlayerNum%numofplayers].getName()+" Won The Round and got 1000$ bonus!");
			game.getPanel_8().initPhrasePanel();
			game.endRound(currentPlayerNum);
		}
		else{ 
			currentPlayerNum++;
		PlayRound();
		}
	}


	protected void SetPlayersScore(int winner) {
		players[winner].setScore(players[winner].getScore() + roundBonus);
	}


	public void setScore(int score) {
		game.setScore(currentPlayerNum%numofplayers, score);
		game.setPlayerscores(currentPlayerNum % numofplayers, game.getPlayerscores()[currentPlayerNum%numofplayers]+score);	
	}


}